#include <iterator>
#include <iostream>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::istream_iterator;
using std::ostream_iterator;

int test0()
{
    //istream_iterator内部一定有一个操作封装了以下两句
    //int num = 0;
    //cin >> num;

    vector<int> numbers(5);
    cout << "numbers中的原始值:";
    for(auto & e : numbers) {
        cout << e << " ";
    }
    cout << endl;
    //有参的写法是输入迭代器开始的位置
    istream_iterator<int> isi(cin);
    //无参的写法就是输入迭代器结束的位置
    std::copy(isi, istream_iterator<int>(), numbers.begin());

    cout << "111" << endl;
    ostream_iterator<int> osi(cout, " ");
    std::copy(numbers.begin(), numbers.end(), osi);
    cout << endl;

    return 0;
}

int test1()
{
    cout << "test1()" << endl;
    //vector初始情况下，没有任何数据
    vector<int> numbers;
    cout << "numbers中的原始值:";
    for(auto & e : numbers) {
        cout << e << " ";
    }
    cout << endl;
    //有参的写法是输入迭代器开始的位置
    istream_iterator<int> isi(cin);
    //无参的写法就是输入迭代器结束的位置
    std::copy(isi, istream_iterator<int>(), std::back_inserter(numbers));

    cout << "111" << endl;
    ostream_iterator<int> osi(cout, " ");
    std::copy(numbers.begin(), numbers.end(), osi);
    cout << endl;

    return 0;
}

int main()
{
    /* test0(); */
    test1();
    return 0;
}
